package thinkinjava.c15_generics;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @Auther DRevelation
 * @Date 2020-05-11 上午 10:14
 * @Desc 随机获取一个特定类型的对象
 */
public class RandomList<T> {
    private List<T> list = new ArrayList<>();
    private Random rand = new Random(47);
    public void add(T item) {
        list.add(item);
    }
    public T select() {
        return list.get(rand.nextInt(list.size()));
    }

    public static void main(String[] args) {
        RandomList<String> rs = new RandomList<>();
        for (String s : ("The quick brown fox jump over lazy brown dog").split(" ")) {
            rs.add(s);
        }
        for (int i = 0; i < 11; i++) {
            System.out.println(rs.select() + " ");
        }
    }
}
